exports.addSales = function(req,res){

    //获取参数信息
    var bodyParams = req.routeInfo.bodyParams;

    //新增的用户ID
    var newUserId = 0;

    //判断该手机号是否已经被使用
    function validationPhone(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_username/" + bodyParams.u_phone,
                method : 'GET'
            },
            function (data) {

                if(data.result.data.length > 0){
                   return RES.errorResponse(res,"该手机号已被录入，请勿重复录入！");
                }

                cb();

            }
        )


    }

    //新增销售人员
    function addSales(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.userAdd.Request_Api_Url,
                method : 'POST',
                data   : {
                    u_username      : bodyParams.u_phone,
                    u_password      : '123456',
                    u_nickname      : bodyParams.u_name,
                    u_phone         : bodyParams.u_phone,
                    u_create_time   : common.nowTime(false),
                    u_is_activation : 1,
                    u_type          : bodyParams.os_type,
                    u_master_osid   : bodyParams.os_id
                }
            },
            function (data) {

                newUserId = data.result;

                cb();
            }
        )

    }

    //将该员工加入节点
    function addUserToNode(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.userOrganizationalMiddleAdd.Request_Api_Url,
                method : 'POST',
                data   : {
                    uom_osid : bodyParams.os_id,
                    uom_uid  : newUserId

                }
            },
            function (data) {

                cb();
                
            }
        )
    }

    F.Serial([validationPhone,addSales,addUserToNode],() => {
        RES.successResponse(res);
    })

}